//
//  NSString+Extention.m
//  ToastDemo
//
//  Created by seed on 2016/11/25.
//  Copyright © 2016年 WTFSSD. All rights reserved.
//

#import "NSString+Extention.h"

@implementation NSString (Extention)
-(NSString*(^)(id))add{
    return ^(id s){
        return  [NSString stringWithFormat:@"%@%@",self,s];
    };
}


-(NSString *(^)(NSString *))rm_s{
    return ^(NSString * s){
        return [self stringByReplacingOccurrencesOfString:s withString:@""];
    };
}


-(NSString *(^)(NSString *))rm_c{
    return ^(NSString * c){
        NSString * mstr = [[NSString alloc] initWithString:self];
       const char *  ss = [c cStringUsingEncoding:NSUTF8StringEncoding];
        for (int i  = 0 ; i<c.length; i++) {
            char cc = ss[i];
            mstr =  [mstr stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%c",cc] withString:@""];
        }
        return mstr;
    };
}

-(NSString *(^)(NSString *, NSString *))rp_s{
    return ^(NSString * sours,NSString * rps){
        return [self stringByReplacingOccurrencesOfString:sours withString:rps];
    };
}


-(NSString *(^)())formatUnicode{
    return ^(){
        NSString *tempStr1 = self.rp_s(@"\\u",@"\\U");
        NSString *tempStr2 =  [tempStr1 stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];
        NSString *tempStr3 = [[@"\"" stringByAppendingString:tempStr2] stringByAppendingString:@"\""];
        NSData *tempData = [tempStr3 dataUsingEncoding:NSUTF8StringEncoding];
        NSString* returnStr = [NSPropertyListSerialization propertyListWithData:tempData
                                                                        options:NSPropertyListImmutable
                                                                         format:NULL
                                                                          error:nil];
        return returnStr;
    };
}

-(CGSize)sizeInAre:(CGSize)are font:(UIFont*)font{
    NSDictionary * attribuite = @{NSFontAttributeName:font};
    CGSize textSize;
    textSize = [self boundingRectWithSize:are options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:attribuite context:nil].size;
    return textSize;
}

-(NSString *)add:(id)obj{
    return self.add(obj);
}

-(NSString *)rm_c:(NSString *)c{
    return self.rm_c(c);
}

-(NSString *)rm_s:(NSString *)s{
    return self.rm_s(s);
}

-(NSString *)rp_s:(NSString *)sours with:(NSString *)rps{
    return self.rp_s(sours,rps);
}

-(NSString *)formatunicode{
    return self.formatUnicode();
}


@end
